package com.example.demoredisqueue;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

@Slf4j
@RestController
public class TestController {

    @Resource(name = "redisTemplate")
    RedisTemplate redis;

    @PostMapping("/redis/mq/product")
    public String redisMqProduct(@RequestBody Map<String, String> map) {
        Collection<String> values = map.values();
        if (!CollectionUtils.isEmpty(values)) {
            Iterator<String> iterator = values.iterator();
            while (iterator.hasNext()) {
                String str = iterator.next();
                Long size = redis.opsForList().rightPush("redisMqList", str);//从右向list添加元素
                String logStr = "向[redisMqList]中推送信息 = [" + str + "], 消息总数为[" + size + "]条";
                log.info(logStr);
            }
        }
        return "send ok!";
    }
//————————————————
//    版权声明：本文为CSDN博主「老王头的笔记」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
//    原文链接：https://blog.csdn.net/m0_37606574/article/details/88977936


}
